/**
 *
 */
package com.laputacastle.dr.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.Serializable;

/**
 * Description: webapi响应实体类，可序列化成json格式
 * @version 1.0
 */
public class Response implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * success
     * @return
     */
    public static final Response success() {
        return new Response("0000", "成功");
    }
    /**
     * errorNeedLogin
     * @return
     */
    public static final Response errorNeedLogin() {
        return new Response("0001", "请登录后访问");
    }
    /**
     * errorInvalidSign
     * @return
     */
    public static final Response errorInvalidSign() {
        return new Response("0002", "请求签名验证不通过");
    }
    /**
     * errorExpired
     * @return
     */
    public static final Response errorExpired() {
        return new Response("0003", "请求已过期");
    }
    /**
     * 
     * @return
     */
    public static final Response errorPermissionsDenied() {
        return new Response("0004", "权限不足，您无权进行此操作");
    }
    /**
     * 
     * @return
     */
    public static final Response errorInvalidArgs() {
        return new Response("0005", "请求参数不合法");
    }
    /**
     * errorFileNotFound
     * @return
     */
    public static final Response errorFileNotFound() {
        return new Response("0006", "文件或记录不存在");
    }
    
    /**
     * fileExist(
     * @return
     */
    public static final Response fileExist() {
        return new Response("0007", "文书已经存在");
    }
    /**
     * 
     * @return
     */
    public static final Response errorLoginUser() {
        return new Response("0008", "登录用户不一致");
    }
    /**
     * 
     * @return
     */
    public static final Response errorInvalidLoginInfo() {
        return new Response("0101", "登录信息不正确");
    }
    /**
     * errorCaseNotFound
     * @return
     */
    public static final Response errorCaseNotFound() {
        return new Response("0501", "请求的案件不存在");
    }
    /**
     * errorSave
     * @return
     */
    public static final Response errorSave() {
        return new Response("9996", "保存失败");
    }
    /**
     * errorNoLicenseInfo
     * @return
     */
    public static final Response errorNoLicenseInfo() {
        return new Response("9997", "未购买产品");
    }
    /**
     * 
     * @return
     */
    public static final Response errorUnknownApiKey() {
        return new Response("9998", "未知请求");
    }
    /**
     * 
     * @return
     */
    public static final Response errorUnknown() {
        return new Response("9999", "未知系统错误");
    }
    /**
     * errorFileisnotexit
     * @return
     */
    public static final Response errorFileisnotexit() {
        return new Response("8006", "存在电子卷宗目录信息，但未找到电子卷宗文件信息!");
    }
    /**
     * errorRecognition
     * @return
     */
    public static final Response errorRecognition() {
        return new Response("8007", "该卷宗无法完成识别，请手动复制");
    }

    /* 盗窃普通证据审查 begin */
    public static final Response SPLIT_ERROR_NO_RELATION = new Response(
            "102401", "拆分失败，无挂接卷宗！");

    public static final Response SPLIT_ERROR_ONLY_ONE_FILE = new Response(
            "102402", "该证据只包含一页卷宗，无法拆分！");

    public static final Response SPLIT_ERROR_ON_ONE_PAGE = new Response(
            "102403", "该文件是证据的第一页，无法拆分！");

    /* 盗窃普通证据审查 end */
    /* 危驾速裁事实审查 */
    /**
     * 
     * @return
     */
    public static final Response errorFactorNotRecognize() {
        return new Response("0802", "实体识别识别要素失败！");
    }

    private String code;

    private String msg;

    private Serializable data;

    public Response() {
    }
    /**
     * Response
     * @param returnCode
     * @param returnMsg
     */
    public Response(String returnCode, String returnMsg) {
        this(returnCode, returnMsg, null);
    }
    /**
     * Response
     * @param returnCode
     * @param returnMsg
     * @param data
     */
    public Response(String returnCode, String returnMsg, Serializable data) {
        this.code = returnCode;
        this.msg = returnMsg;
        this.data = data;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the msg
     */
    public String getMsg() {
        return msg;
    }

    /**
     * @param msg the msg to set
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * @return the data
     */
    public Serializable getData() {
        return data;
    }

    /**
     * @param data the data to set
     */
    public void setData(Serializable data) {
        this.data = data;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return toJsonString();
    }

    /**
     * toJsonString
     * @return
     */
    public String toJsonString() {
        return JSON.toJSONString(this,
            SerializerFeature.DisableCircularReferenceDetect,
            SerializerFeature.WriteMapNullValue);
    }
    /**
     * success
     * @param data
     * @return
     */
    public static final Response success(Serializable data) {
        Response r = success();
        r.setData(data);
        return r;
    }
    /**
     * fileExist
     * @param data
     * @return
     */
    public static final Response fileExist(Serializable data) {
        Response r = fileExist();
        r.setData(data);
        return r;
    }
}
